package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.dto.DishDTO;
import com.sky.entity.Dish;
import com.sky.result.Result;
import com.sky.service.DishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: DishController
 * Package: com.sky.controller.user
 * Description:
 *
 * @Author 八云
 * @Create 2025/3/22 23:51
 * @Version 1.0
 */

@RestController("userDishController")
@RequestMapping("/user/dish")
@Api(tags = "菜品相关接口")
@Slf4j
public class DishController {

    @Autowired
    private DishService dishService;

    /**
     * 根据菜品分类id查询菜品
     *
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("查询菜品分类")
    @Cacheable(value = "dishCache", key = "#categoryId")
    public Result<DishDTO[]> list(Long categoryId) {
        log.info("查询菜品分类:{}", categoryId);
        //查询起售中的菜品
        return Result.success(dishService.list(Dish.builder()
                .status(StatusConstant.ENABLE)
                .categoryId(categoryId)
                .build()));


    }
}
